/* eslint-disable */
const withCss = require('@zeit/next-css')
const withLess = require('@zeit/next-less')
const withImages = require('next-images');
const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');
const withPlugins = require("next-compose-plugins");
const withTM = require('next-transpile-modules');
const cssLoaderGetLocalIdent = require("css-loader/lib/getLocalIdent.js");
const path = require('path');
const isProd = process.env.NODE_ENV === 'production'
const isCDN = process.env.NODE_CND === 'local'
console.warn(`BUILD assetPrefix: ${isProd ? (isCDN ? '' : '//f3-md.veimg.cn/meadinindexnew/m') : ''}`);
const nextConfig = {
  assetPrefix: isProd ? (isCDN ? '' : '//f3-md.veimg.cn/meadinindexnew/m') : '',
  webpack: (config) => {
    if(config.externals){
      const includes = [/antd-mobile/];
      config.externals = config.externals.map(external => {
        if (typeof external !== 'function') return external;
        return (ctx, req, cb) => {
          return includes.find(include =>
            req.startsWith('.')
              ? include.test(path.resolve(ctx, req))
              : include.test(req)
          )
            ? cb()
            : external(ctx, req, cb);
        };
      });
    }
    config.plugins.push(
        new FilterWarningsPlugin({
            exclude: /mini-css-extract-plugin[^]*Conflicting order between:/,
        })
    );
    return config
  },
}
const wp = withPlugins([
  [withCss, {
    cssModules: true,
    cssLoaderOptions: {
      localIdentName: "[local]___[hash:base64:5]",
      getLocalIdent: (context, localIdentName, localName, options) => {
        let hz = context.resourcePath.replace(context.rootContext, "");
        if (/node_modules/.test(hz)) {
          return localName;
        } else {
          return cssLoaderGetLocalIdent(
            context,
            localIdentName,
            localName,
            options
          ); 
        }
      }
    },
    transpileModules: ["antd-mobile"]
  }], 
  [withLess, {
    cssModules: true,
    lessLoaderOptions: {
      javascriptEnabled: true,
      importLoaders: 1,
    }
  }], 
  withImages,
  withTM,
  ], nextConfig)
module.exports = wp
